package net.minhdiep.androiddialoglistener;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import net.minhdiep.androiddialoglistener.components.AlertDialogFragment;import net.minhdiep.androiddialoglistener.view.TwoButtons;

public class MainActivity extends FragmentActivity implements AlertDialogFragment.AlertDialogListener, TwoButtons.OnButtonListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button subListenerBtn = (Button) findViewById(R.id.sub_listener_btn);
        Button subBroadcastReceiverBtn = (Button) findViewById(R.id.sub_broadcast_receiver_btn);
        Button locationServiceBtn = (Button) findViewById(R.id.location_service_btn);
        Button textureViewBtn = (Button) findViewById(R.id.texture_view_btn);

        subListenerBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                DialogFragment dialog = new AlertDialogFragment("This will start Download Xml Listener!", ListenerActivity.class);
                dialog.show(getSupportFragmentManager(), "AlertDialogFragment");
            }

        });

        subBroadcastReceiverBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                DialogFragment dialog = new AlertDialogFragment("This will start Download Xml Broadcast Receiver!", BroadcastReceiverActivity.class);
                dialog.show(getSupportFragmentManager(), "AlertDialogFragment");
            }

        });

        locationServiceBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                DialogFragment dialog = new AlertDialogFragment("This will start Location Service!", LocationServiceActivity.class);
                dialog.show(getSupportFragmentManager(), "AlertDialogFragment");
            }

        });

        textureViewBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                DialogFragment dialog = new AlertDialogFragment("This will start Texture View!", TextureViewActivity.class);
                dialog.show(getSupportFragmentManager(), "AlertDialogFragment");
            }

        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onDialogPositiveClick(DialogFragment dialog, Class cls) {
        Intent intentSubActivity = new Intent(this, cls);
        startActivity(intentSubActivity);
    }

    @Override
    public void onDialogNegativeClick(DialogFragment dialog) {
        dialog.dismiss();
    }

    @Override
    public void onSayHelloBtnClick() {
        Toast.makeText(getApplicationContext(), "Hello Android Drawer...", Toast.LENGTH_LONG).show();

        Intent intentNavDrawer = new Intent(this, NavDrawerActivity.class);
        startActivity(intentNavDrawer);

    }

    @Override
    public void onSayGoodbyeBtnClick() {
        Toast.makeText(getApplicationContext(), "Goodbye Android...", Toast.LENGTH_LONG).show();
    }
}
